package com.qifan.alb2b.dao;


import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.cqcis.base.orm.jdbc.JdbcUtil;
import com.qifan.alb2b.domain.PictureInfoDomain;
import com.qifan.alb2b.util.DataGridModel;
import com.qifan.alb2b.util.Page;

@Repository
public class PictureInfoDao extends BaseDao{
	public List<PictureInfoDomain>	queryAll(){
		String sql="select * from pictureInfo order by sortNo asc";
		return JdbcUtil.queryForList(this, PictureInfoDomain.class, sql);
	}
	/**
	 * 根据条件分页查询图片信息
	 * @param dgm 分页参数
	 * @param uqp 配置查询参数
	 * @return Page对象（分页信息&分页数据）
	 */
	public Page query(DataGridModel dgm,PictureInfoDomain uqp){
		/* 构建sql */
		StringBuilder sql=new StringBuilder();
		List<Object> params=new ArrayList<Object>();
		sql.append("select * from pictureinfo where pictureName like ? order by sortNo asc");
		params.add("%"+uqp.getPictureName()+"%");
		return super.queryObjByPage(sql.toString(), dgm.getRows(), dgm.getPage(), params, PictureInfoDomain.class);
	}
	
	public PictureInfoDomain getPictureById(String id){
		String sql="select * from pictureinfo where pictureid=?";
		List<PictureInfoDomain> list= JdbcUtil.queryForList(this, PictureInfoDomain.class, sql, id);
		if(list.size()>0)
			return list.get(0);
		return null;
	}
	
	/**
	 * 增加一个图片
	 * @param pictureInfoDomain
	 */
	public void add(PictureInfoDomain pictureInfoDomain){
		super.addObj(pictureInfoDomain);
	}
	
	public void update(PictureInfoDomain pictureInfoDomain){
		super.updateObj(pictureInfoDomain, "pictureId");
	}
	
	/**
	 * 批量删除
	 * @param ids
	 */
	public void delete(String[] ids){
		StringBuilder delSql=new StringBuilder();
		delSql.append("delete from pictureinfo where pictureid in(");
		for(int i=0;i<ids.length-1;i++){
			System.out.println(ids[i]);
			delSql.append("?,");
		}
		delSql.append("?)");
		this.getJdbcTemplate().update(delSql.toString(), ids);
	}
}